package com.notify;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;

public class NetworkCustom extends Activity {

	public String getXmlFromUrl(String url) {
		String xml = null;

		try {
			// defaultHttpClient
			DefaultHttpClient httpClient = new DefaultHttpClient();
			HttpPost httpPost = new HttpPost(url);

			HttpResponse httpResponse = httpClient.execute(httpPost);
			HttpEntity httpEntity = httpResponse.getEntity();
			xml = EntityUtils.toString(httpEntity);

		} catch (UnsupportedEncodingException e) {
			Intent in = new Intent(getApplicationContext(), LoginActivity.class);
			finish();
			startActivity(in);
			Toast.makeText(NetworkCustom.this, "Error encoding ",
					Toast.LENGTH_LONG).show();
		} catch (ClientProtocolException e) {
			Intent in = new Intent(getApplicationContext(), LoginActivity.class);
			finish();
			startActivity(in);
			Toast.makeText(NetworkCustom.this, "Error client protocol ",
					Toast.LENGTH_LONG).show();
		} catch (IOException e) {
			Intent in = new Intent(getApplicationContext(), LoginActivity.class);
			finish();
			startActivity(in);
			Toast.makeText(NetworkCustom.this, "Error log ", Toast.LENGTH_LONG)
					.show();
		}
		// return XML
		return xml;
	}

}